<?php 
namespace app\admin\controller;

use cmf\controller\AdminBaseController;
use cmf\controller\BaseController;
use think\Db;

	class WxsiteController extends BaseController
	{

		public function index(){
			// $weekarray=array("日","一","二","三","四","五","六");
			// // echo date("Y-m-d",strtotime('+1 day'));
			// // exit;
			// strtotime(date('Y-m-d'));
			// echo $weekarray[date("w",time())];

			$where['s.status']=1;
			$incubator_id = $this->request->param('incubator_id');
			if($incubator_id){
				$where['s.incubator_id']=$incubator_id;	
			}elseif(!empty(session('incubator_id'))){
				$where['s.incubator_id']=session('incubator_id');	
			}else{
				$where['s.incubator_id']=1;
			}		
			$site_types = $this->request->param('site_type_id','');

			if($site_types){
				$where['site_type_id'] = $site_types;	
			}
			/**搜索条件**/
			$site_name = $this->request->param('site_name');
			$address = $this->request->param('address');

			if ($site_name) {
				$where['site_name'] = ['like', "%$site_name%"];
			}

			if ($address) {
				$where['s.address'] = ['like', "%$address%"];
			}
			$equipments=$this->equipments();
			$list=Db::name('site')->alias('s')->where($where)->join('incubator i','i.id=s.incubator_id')->field('s.id,s.site_name,s.site_type_id,s.start_time as stime,s.equipments,s.other_equipments,s.end_time as etime,is_audit,s.pic,s.price,i.site_service_price')->order('id','desc')->select();
			$list=json_decode(json_encode($list),true);
			$i=8;
			$j=0;
			$s=0;
			for($i;$i<=20;$i++){
				for($s=0;$s<2;$s++){
					$f=$s*30;
					if(!$f){
						$f='00';
						// echo $f;
					}
					// $j=$s*30;
					$times[] = $i.':'.$f;
					
				}
			}

			//exit;
			foreach ($list as $key => $value) {
				//var_dump($time);
				$ss=explode(':',$value['stime']);
				$ee=explode(':',$value['etime']);
				$arr[]=$value['stime'];
				$arr[]=$value['etime'];
				if($ss[1] !=30 ){
					$arr[]=$ss[0].':30';
				}
				if($ee[1] !=0 ){
					$arr[]=$ee[0].':00';
				}
				$count=$ee[0]-$ss[0];
				for($g=1;$g<$count;$g++){
					$arr[]=$ss[0]+$g.':00';
					$arr[]=$ss[0]+$g.':30';
					
				}
				//var_dump($arr);

			// 	foreach ($times as $keys => $values) {
			// 		if(in_array($values, $arr)){
			// 			$list[$key]['apply'][]=array('selected'=>3,'time'=>$values);
			// 		}else{
			// 			$list[$key]['apply'][]=array('selected'=>1,'time'=>$values);
			// 		}
			// 	}
			// 	unset($arr);
				
			// }
				$count=count($arr);
				$last_num=1;
				foreach ($times as $keys => $values) {
					if(in_array($values, $arr)){
						
						if($last_num != $count){
							$list[$key]['apply'][]=array('selected'=>3,'time'=>$values);	


						}else{
							$list[$key]['apply'][]=array('selected'=>1,'time'=>$values,'no_choose'=>1);
						}
						$last_num++;
					}else{
						$list[$key]['apply'][]=array('selected'=>1,'time'=>$values);
					}
				}
				unset($arr);
				
			}
				// var_dump($times);
				// exit;
			// 	$count=count($arr);
			// 	$last_num=1;
			// 	foreach ($times as $keys => $values) {
			// 		if(in_array($values, $arr)){
			// 			if($last_num==$count-1){
			// 				$list[$key]['apply'][$keys]['last']=1;
			// 			}
			// 			if($last_num!=$count){
			// 				$list[$key]['apply'][$keys]['selected']= 3;
			// 				$list[$key]['apply'][$keys]['time'] = $values;
						   
			// 		    }else{
			// 		    	$list[$key]['apply'][$keys]=array('selected'=>'','time'=>$values);
			// 		    }
			// 			 $last_num++;
			// 		}else{
			// 			$list[$key]['apply'][$keys]=array('selected'=>1,'time'=>$values);
			// 		}
			// 	}
			// 	unset($arr);
				
			// }
		
			$day=$this->request->param('num');
			for($i=0;$i<count($list);$i++){
				//echo $i;
				
				if(!empty($list[$i]['equipments'])){
					$arr=explode(',', $list[$i]['equipments']);
				}else{
					$arr = array();
				}
				if(!empty($list[$i]['other_equipments'])){
					$other_arr=explode(',', $list[$i]['other_equipments']);
				}else{
					$other_arr = array();
				}
				
				/*当天*/
				$time[1]['s']=strtotime(date("Y-m-d"));
				$time[1]['e']=strtotime(date("Y-m-d",strtotime('+1 day')));
				$time[2]['s']=strtotime(date("Y-m-d",strtotime('+1 day')));
				$time[2]['e']=strtotime(date("Y-m-d",strtotime('+2 day')));
				$time[3]['s']=strtotime(date("Y-m-d",strtotime('+2 day')));
				$time[3]['e']=strtotime(date("Y-m-d",strtotime('+3 day')));
				$time[4]['s']=strtotime(date("Y-m-d",strtotime('+3 day')));
				$time[4]['e']=strtotime(date("Y-m-d",strtotime('+4 day')));
				$time[5]['s']=strtotime(date("Y-m-d",strtotime('+4 day')));
				$time[5]['e']=strtotime(date("Y-m-d",strtotime('+5 day')));
				$time[6]['s']=strtotime(date("Y-m-d",strtotime('+5 day')));
				$time[6]['e']=strtotime(date("Y-m-d",strtotime('+6 day')));
				$time[7]['s']=strtotime(date("Y-m-d",strtotime('+6 day')));
				$time[7]['e']=strtotime(date("Y-m-d",strtotime('+7 day')));
				foreach ($time as $key => $value) {
					if($key==$day){
						$condition='audit_status = 2';
						$where_apply['site_id']=$list[$i]['id'];
						//$where_apply['site_id']=1;
						$where_apply['start_time']=array('egt',$value['s']);
						$where_apply['end_time']=array('elt',$value['e']);
						$apply_info=db('site_apply_info')->where($where_apply)->where($condition)->field('id,start_time,end_time,staff_id')->select();
						$apply_info=json_decode(json_encode($apply_info),true);
						foreach ($apply_info as $ks => $vs) {
							//var_dump($list[$i]);
							//var_dump($vs);
							// $stime= date("H:i",$vs['start_time']);
							// $etime= date("H:i",$vs['end_time']);

							$s = intval($vs['start_time'])/60*60;
							$e = intval($vs['end_time'])/60*60;
							while ($s<=$e){
								$stime= date("H:i",$s);
								$arrs[]=$stime;
							    $s += 1800;
							}
							/*$ss=explode(':',$stime);
							$ee=explode(':',$etime);
							$arrs[]=$stime;
							$arrs[]=$etime;
							if($ss[1] !=30 ){
								$arrs[]=$ss[0].':30';
							}
							if($ee[1] !=0 ){
								$arrs[]=$ee[0].':00';
							}
							$count=$ee[0]-$ss[0];
							for($g=1;$g<$count;$g++){
								$arrs[]=$ss[0]+$g.':00';
								$arrs[]=$ss[0]+$g.':30';

							}*/



							//var_dump($arrs);
							//exit;

							$count=count($arrs);
							$last_num=1;
							foreach ($list[$i]['apply'] as $k2 => $v2) {


								if(in_array($v2['time'], $arrs) || in_array('0'.$v2['time'], $arrs)){
									//	echo $v2['time'].'###';
									if($last_num==$count-1){
										$list[$i]['apply'][$k2]['last']=1;
									}
									if($last_num==1){
										$list[$i]['apply'][$k2]['first']=1;
									}
									if($last_num!=$count){
										//echo $list[$i]['id'].'&&'.$last_num .'@' .$count."<br/>";
										//echo $count.'^^';
										$list[$i]['apply'][$k2]['staff_id']=$vs['staff_id'];
										$list[$i]['apply'][$k2]['staff_name']=db('staff_member')->where('id',$vs['staff_id'])->value('staff_name');
										$list[$i]['apply'][$k2]['selected']=2;
										//$list[$i]['apply'][$k2]['num']=$last_num;
										//$list[$i]['site_id']=
									}else{
										//	echo $list[$i]['id'].'&&'.$last_num .'**' .$count."<br/>";
										$list[$i]['apply'][$k2]['staff_id']=$vs['staff_id'];
										$list[$i]['apply'][$k2]['staff_name']=db('staff_member')->where('id',$vs['staff_id'])->value('staff_name');
									    //$list[$i]['apply'][$k2]['selected'] = '';
									    $list[$i]['apply'][$k2]['selected'] = 3;
									}

									$last_num++;

								}
								//echo $last_num.'/';

								//echo '#'.$count.'#';
							}
						//	exit;
							unset($arrs);
						}
					}
				}
				if(count($arr) > 0){
					for($s=0;$s<count($arr);$s++){

						$list[$i]['equipment'][$s]['equipment_name']=get_cate_name(16,$arr[$s]);
						$list[$i]['equipment'][$s]['equipment_id']=$arr[$s];

					}
				}
				
				if(count($other_arr) > 0){
					for($s=0;$s<count($other_arr);$s++){

						$list[$i]['other_equipment'][$s]['equipment_name']=get_cate_name(16,$other_arr[$s]);
						$list[$i]['other_equipment'][$s]['equipment_id']=$other_arr[$s];

					}
				}

				unset($list[$i]['other_equipments']);
				unset($list[$i]['equipments']);
	
				$url=cmf_get_image_preview_url($list[$i]['pic']);
				$list[$i]['pic']=str_replace('http:','https:',$url);
				$list[$i]['site_type']=site_type(5,$list[$i]['site_type_id']);
			}
			return json($list);


		}
		/*添加会议室预约*/
		function add_apply_site(){
			$data['site_id'] = $this->request->param('site_id');
		//	$data['site_id'] = $this->request->param('choose_num');
			$data['staff_id'] = $this->request->param('staff_id');
			$data['start_time'] = $this->request->param('start_time');
			$data['end_time'] = $this->request->param('end_time');
			$add=db('site_apply_info')->insert($data);
			if($add){
				return json(array('status'=>1,'mess'=>'预约审核中'));
			}else{
				return json(array('status'=>0,'mess'=>'预约失败'));
			}


		}
		/*会议室取消预约*/
		function cancel_apply_site(){

		// 	$data['site_id'] = $this->request->param('site_id');
		// //	$data['site_id'] = $this->request->param('choose_num');
		// 	$data['staff_id'] = $this->request->param('staff_id');
		// 	$data['start_time'] = $this->request->param('start_time');
		// 	$data['end_time'] = $this->request->param('end_time');
			$data['id'] = $this->request->param('apply_id');
			$pay_status = db('orderlist')->where(array('apply_id'=>$data['id']))->value('pay_status');
			$info = array();
			if(!$pay_status || $pay_status ==1){
				$add=db('site_apply_info')->where($data)->update(array('is_using'=>6,'audit_status'=>3));
				db('orderlist')->where('apply_id',$data['id'])->delete();
               // echo 	db()->getLastSql();
				return json(array('status'=>1,'mess'=>'取消成功'));

				// $info = $this->back_money($data['id']);
			}elseif($pay_status ==2){
				$info = $this->back_money($data['id']);	
				if($info){
					$add=db('site_apply_info')->where($data)->update(array('is_using'=>6,'audit_status'=>3));
					db('orderlist')->where('apply_id',$data['id'])->delete();
				// if($add){
				// 	return json(array('status'=>1,'mess'=>'取消成功'));
				// }else{
				// 	return json(array('status'=>0,'mess'=>'取消失败'));
				// }
					return json(array('status'=>1,'mess'=>'取消成功'));
				}else{
					return $info;
				}

			}
			
			//var_dump($info);
			// if($info){
			// 	$add=db('site_apply_info')->where($data)->update(array('is_using'=>6,'audit_status'=>3));
			
			// 	return json(array('status'=>1,'mess'=>'取消成功'));
			// }else{
			// 	return $info;
			// }



		}
		function back_money($apply_id){
			$url = config('back_url');
			//$data['token'] = $this->request->param('token');
			file_put_contents('/hl/log.txt',print_r('%%%%',true),FILE_APPEND);
			file_put_contents('/hl/log.txt',print_r($apply_id,true),FILE_APPEND);
			file_put_contents('/hl/log.txt',print_r('………………',true),FILE_APPEND);
			$order_sn = db('orderlist')->where('apply_id',$apply_id)->value('order_sn');
			$data['order_sn'] = $order_sn;
			file_put_contents('/hl/log.txt',print_r($order_sn,true),FILE_APPEND);
			file_put_contents('/hl/log.txt',print_r('&&&&',true),FILE_APPEND);
			$info = sqcurl($url,'post',$data,array());
			file_put_contents('/hl/log.txt',print_r($info,true),FILE_APPEND);
			//var_dump($info);
			if(json_decode($info)->code == 1){
				$set = db('orderlist')->where('apply_id',$apply_id)->setField('pay_status',1);
				return $set;
			}else{
				return 0;
			}
			
		}
		/*员工会议室预约列表 type ==1 预约成功 2进行中3未成功（取消，失败）4审核中*/
		function get_apply_list(){
			$where=array();
			$condition='';
			$data['staff_id'] = $this->request->param('staff_id');
			$data['type'] = $this->request->param('type');
			if($data['type']==1){
				$where=' staff_id = "'.$data['staff_id'].'" and start_time > "'.time().'" ' ;
				$condition='audit_status =2';
			}
			if($data['type']==2){
				$where=' staff_id = "'.$data['staff_id'].'" and start_time < "'.time().'"  and end_time > "'.time().'" ' ;
				// $condition='(is_audit = 1 ) or (is_audit =2 and audit_status =2)';
				$condition=' audit_status =2 ';
			}
			if($data['type']==3){
				$where=' staff_id = "'.$data['staff_id'].'" ' ;
				$condition='is_using = 6 or audit_status = 3';
			}
			if($data['type']==4){
				
				$condition = '  end_time >= "'.time().'" and staff_id = "'.$data['staff_id'].'" and audit_status =1 ';
			}
			$apply_list=db('site_apply_info')->alias('s')->where($where)->where($condition)->field('s.id as apply_id,s.site_id,s.start_time,s.end_time,s.audit_status,s.audit_remark as remark ,s.is_using')->order('add_time desc')->select();
			
			$apply_list = json_decode(json_encode($apply_list),true);
			foreach ($apply_list as $k => $v) {
				$apply_list[$k]['pay_status'] = db('orderlist')->where('apply_id',$v['apply_id'])->value('pay_status');
			}
			foreach ($apply_list as $key => $value) {
				$site_info=db('site')->where('id',$value['site_id'])->field('site_name,pic')->find();
				$apply_list[$key]['site_name']=$site_info['site_name'];
				$url=cmf_get_image_preview_url($site_info['pic']);
				$apply_list[$key]['site_img']=str_replace('http:','https:',$url);

				

				
			}
			// echo db('site_apply_info')->getLastSql();
			// var_dump($apply_list);
			
			return json($apply_list);
		}
		/*取消会议室*/

		/*设备*/
			function equipments(){
		
			$where=array('t.name'=>'设备');
		
				 //$eqs = db('site')->where('id',$site_id)->field('equipments,other_equipments')->find(); 
				// $eqs = db('site')->where('id',$site_id)->field('equipments,other_equipments')->select(); 
				/* var_dump($eqs);*/
				
					//var_dump($list);
					//echo db()->getLastSql();
					//exit;
				
			
			//var_dump($list);
			$list=db("category_type")->alias('t')->join('category c','t.id=c.type_id')->field('c.id,c.name')->where($where)->select();
			return json($list);
		}

		function equipment_list(){
			$site_id = $this->request->param('site_id');
			$where=array('t.name'=>'设备');
			if(!empty('$site_id')){
				 //$eqs = db('site')->where('id',$site_id)->field('equipments,other_equipments')->find(); 
				 $eqs = db('site')->where('id',$site_id)->field('equipments,other_equipments')->select(); 
				/* var_dump($eqs);*/
				foreach ($eqs as $key => $value) {

					$wheres['c.id'] = array('in',$value);
					$list[$key]=db("category_type")->alias('t')->join('category c','t.id=c.type_id')->field('c.id,c.name')->where($wheres)->where($where)->select();
					//var_dump($list);
					//echo db()->getLastSql();
					//exit;
				}
			}
			//var_dump($list);
			//$list=db("category_type")->alias('t')->join('category c','t.id=c.type_id')->field('c.id,c.name')->where($where)->select();
			return json($list);
		}

		/*园区添加*/		
		public function addSite(){
			//$_POST['start_time']='0000-00-00 00:00:00';
			if($_POST){
			
				$data['site_name'] = $this->request->param('site_name','');
				$data['incubator_id'] = $this->request->param('incubator_id',0,'intval');
				$data['site_type_id'] = $this->request->param('site_type_id',1);
				$data['price'] = $this->request->param('price',0);
				$data['mobile'] = $this->request->param('mobile','');
				$data['people'] = $this->request->param('people',0,'intval');	
			//场地正常一天开始到结束的时间
				
				// echo $time;
				// exit;
				$data['start_time'] = $this->request->param('start_time','');
				$data['end_time'] = $this->request->param('end_time','');
				$data['pic'] = $this->request->param('pic','');
				$data['pic'] = $this->request->param('pic','');
				$data['site_sketch'] = $this->request->param('site_sketch','');
				$data['address'] = $this->request->param('address');
				$data['status'] = $this->request->param('status',1);
				$data['sort'] = $this->request->param('sort',0);
				if(!$data['start_time']){
					unset($data['start_time']);
				}
				if(!$data['end_time']){
					unset($data['end_time']);
				}
			// echo $incubator_name ;
			// if($type_id==1){
			// 	$station_	
			// }					

			// echo $type_id;
	// var_dump($data);
	// 			exit;
				$add=Db::name('site')->insert($data);

				if($add){
					$this->success('添加成功','sit/index');
				}else{
					$this->error('添加失败');
				}	
			}else{
				$where=array();	
				if(session('incubator_id')){
					$where['id']=session('incubator_id');
				}
				$incubator_list=db('incubator')->where(array('status'=>1))->where($where)->field('id,incubator_name')->select();
				$site_type=$this->local_site_type();
				$this->assign('site_type',$site_type);
				$this->assign('incubator_list',$incubator_list);
				return $this->fetch();
			}
			





		}
		/*场地类型*/
		function site_type(){
			$data['incubator_id'] = $this->request->param('incubator_id',1);
			$where=array('t.name'=>'场地类型');
			$list=db("category_type")->alias('t')->join('category c','t.id=c.type_id')->field('c.id,c.name,c.img')->where($where)->select();
			$list=json_decode(json_encode($list),true);

			$ib_list = db('ib_stype_img')->where('incubator_id',$data['incubator_id'])->field('img_url,site_type_id')->select();
			
  
			foreach ($list as $key => $value) {
				
					foreach ($ib_list as $k => $v) {
						if($v['site_type_id'] == $value['id']){

							$list[$key]['img'] = $ib_list[$k]['img_url'];
							//break;
						}
					}
				

			}
		
			foreach ($list as $key => $value) {
				if($value['img']){
					if($_SERVER['HTTP_HOST'] == 'localhost'){
						$list[$key]['img']=config('local_img_host').$value['img'];
					}else{
						
					 $list[$key]['img']=config('img_host').$value['img'];
					}
				}
				$condition=' site_type_id = "'.$value['id'].'"  and incubator_id = "'.$data['incubator_id'].'"';
				$site_info=db('site')->where($condition)->find();
				if(empty($site_info)){
					unset($list[$key]);
				}
				
			}
			//var_dump($list);
			return json($list);
		}
			function local_site_type(){
			// echo config('img_host');
			
			// exit;

			$where=array('t.name'=>'场地类型');
			$list=db("category_type")->alias('t')->join('category c','t.id=c.type_id')->field('c.id,c.name,c.img')->where($where)->select();
			$list=json_decode(json_encode($list),true);
			// foreach ($list as $key => $value) {
			// 	$condition=' site_type_id = "'.$value['id'].'" ';
			// 	$site_info=db('site')->where($condition)->find();
			// 	if(empty($site_info)){
			// 		unset($list[$key]);
			// 	}
			// }
			foreach ($list as $key => $value) {
				if($value['img']){
					$list[$key]['img']=config('img_host').$value['img'];
				}
				$condition=' site_type_id = "'.$value['id'].'" ';
				$site_info=db('site')->where($condition)->find();
				if(empty($site_info)){
					unset($list[$key]);
				}
				
			}

			return json($list);
		}
		function incubator_site_type(){
		
			$data['incubator_id'] = $this->request->param('incubator_id',1);
			$where=array('t.name'=>'场地类型');
			$list=db("category_type")->alias('t')->join('category c','t.id=c.type_id')->field('c.id,c.name,c.img')->where($where)->select();
			$list=json_decode(json_encode($list),true);

			$ib_list = db('ib_stype_img')->where('incubator_id',$data['incubator_id'])->field('img_url,site_type_id')->select();
			
  
			foreach ($list as $key => $value) {
				
					foreach ($ib_list as $k => $v) {
						if($v['site_type_id'] == $value['id']){

							$list[$key]['img'] = $ib_list[$k]['img_url'];
							//break;
						}
					}
				

			}
		
			foreach ($list as $key => $value) {
				if($value['img']){
					if($_SERVER['HTTP_HOST'] == 'localhost'){
						$list[$key]['img']=config('local_img_host').$value['img'];
					}else{
						
					 $list[$key]['img']=config('img_host').$value['img'];
					}
				}
				$condition=' site_type_id = "'.$value['id'].'"  and incubator_id = "'.$data['incubator_id'].'"';
				$site_info=db('site')->where($condition)->find();
				if(empty($site_info)){
					unset($list[$key]);
				}
				
			}
			//var_dump($list);
			return json($list);
		}
		function meeting_type(){
			// echo config('img_host');
			
			// exit;

			// $where=array('t.name'=>'场地类型');
			// $condition='c.id IN (1,8,10)';
			// $list=db("category_type")->alias('t')->join('category c','t.id=c.type_id')->field('c.id,c.name,c.img')->where($where)->where($condition)->select();
			// $list=json_decode(json_encode($list),true);
		
			// foreach ($list as $key => $value) {
			// 	if($value['img']){
			// 		$list[$key]['img']=config('img_host').$value['img'];
			// 	}
				
			// }
		
			// return json($list);
			$where=array('t.name'=>'场地类型');
			$incubator_id =$this->request->param('incubator_id');
			$condition='c.id IN (1,8,10)';
			$list=db("category_type")->alias('t')->join('category c','t.id=c.type_id')->field('c.id,c.name,c.img')->where($where)->where($condition)->select();
			$list=json_decode(json_encode($list),true);
			$where1 = array();
			if(!empty($incubator_id)){
				$where1['incubator_id'] = $incubator_id;
			}
			foreach ($list as $key => $value) {
				if($value['img']){
					$list[$key]['img']=config('img_host').$value['img'];
				}
				$condition1=' site_type_id = "'.$value['id'].'" ';
				$site_info=db('site')->where($condition1)->where($where1)->find();
				if(empty($site_info)){
					unset($list[$key]);
				}
				
			}

			return json($list);
		}
		/*详情*/
		// public function detailSite(){
		// 	$where=array();
		// 	$id= $this->request->param('id',0,'intval');
		// 	if($id){
		// 		$where['cx_site.id']= $id;
		// 	}else{
		// 		// dump(info_back('','id为空',false));
		// 		// exit;
		// 		return info_back('','id为空',false);
		// 	}
		// //	$detail= Db::name('site')->where($where)->join('cx_incubator','cx_site.incubator_id=cx_incubator.id')->find();
		// 	$detail= Db::name('site')->where($where)->find();
		// 	//var_dump($detail);
		// 	$where=array();	
		// 	if(session('incubator_id')){
		// 		$where['id']=session('incubator_id');
		// 	}
		// 	$incubator_list=db('incubator')->where(array('status'=>1))->where($where)->field('id,incubator_name')->select();
			
		// 	$site_type=$this->site_type();
		// 	$this->assign('site_type',$site_type);
		// 	$this->assign('incubator_list',$incubator_list);
		// 	$this->assign('detail',$detail);
		// 	return $this->fetch();
		// }

		// /*编辑园区*/	
		// public function editSite(){
		// 	if($_POST){
		// 		// dump($_POST);
		// 		// exit;
		// 		$edit = Db::name('site')->update($_POST);
		// 		if($edit){
		// 			$this->success('编辑成功','Sit/index');
		// 		}else{
		// 			$this->success('编辑成功','Sit/index');
		// 		}
		// 	}
		// 	$where=array();
		// 	$id= $this->request->param('id',0,'intval');
		// 	if($id){
		// 		$where['id']= $id;
		// 	}else{
		// 		$this->error('该信息id不能为空');
		// 	}
		// 	// echo $id;
		// 	// exit;
		// 	//dump($where);
		// 	$detail= Db::name('site')->where($where)->find();
		// 	//dump($detail);
		// 	//exit;
		// 	$where=array();	
		// 	if(session('incubator_id')){
		// 		$where['id']=session('incubator_id');
		// 	}

		// 	$incubator_list=db('incubator')->where(array('status'=>1))->where($where)->field('id,incubator_name')->select();
			
		// 	$site_type=$this->site_type();

		// 	$this->assign('site_type',$site_type);
		// 	$this->assign('incubator_list',$incubator_list);
		// 	$this->assign('detail',$detail);
		// 	return $this->fetch();

		// }


		/*删除园区*/
		public function delSite(){
			$data['id']= $this->request->param('id',0,'intval');

			$data['status']=0;

			$del=Db::name('site')->update($data);
			if($del){
				return 1;
			}else{
				return 0;
			}

		}	








		function SendInfo(){
			$info =send_info(1,2,3,4,'pages/mine/mine',520,1509952670428);
			return $info;
			// $data=array();
			// $data['keyword1'] = $this->request->param('keyword1','暂无');
			// $data['keyword2'] = $this->request->param('keyword2','');
			// $data['keyword3'] = $this->request->param('keyword3','');
			// $data['keyword4'] = $this->request->param('keyword4','暂无');
			// $data['page'] =  'pages/mine/mine';
			//  // $data1['staff_id_from']=   $this->request->param('from_id');
			//  // $data1['staff_id_accept']=   $this->request->param('accept_id');
			// // $data['user_id']=db('staff_member')->where('id',$data1['staff_id_accept'])->value('app_userid');
			// $data['user_id']=520;
			// $data['form_id']= $this->request->param('form_id');
		
			// $url= 'http://v2.crejoy.cn/user/send_msg/weixin_yuyue';
			// //var_dump($data);
			// $info = sqcurl($url, 'post', $data, array());
			// return $info;


		}



			/*详情*/
		public function detailSite(){
			$where=array();
			$id= $this->request->param('site_id',0,'intval');
			if($id){
				$where['cx_site.id']= $id;
			}else{
				// dump(info_back('','id为空',false));
				// exit;
				return info_back('','id为空',false);
			}
		//	$detail= Db::name('site')->where($where)->join('cx_incubator','cx_site.incubator_id=cx_incubator.id')->find();
			$detail= Db::name('site')->where($where)->field('site_name,pic,price,mobile,address,people')->find();
				$url=cmf_get_image_preview_url($detail['pic']);
				$detail['pic']=str_replace('http:','https:',$url);
			return json($detail);
			//var_dump($detail);
			// $where=array();	
			// if(session('incubator_id')){
			// 	$where['id']=session('incubator_id');
			// }
			// $incubator_list=db('incubator')->where(array('status'=>1))->where($where)->field('id,incubator_name')->select();
			
			// $site_type=$this->site_type();



			// $equipments_checked=explode(',', $detail['equipments']);
			
			// $equipments=$this->equipments();
			
		}





		





















}
